#ifndef SLTSQL_H
#define SLTSQL_H

#include "tracksql.h"
#include "progsql.h"
#include "slotguts.h"
#include "subgamedata.h"
#include "odbc.h"
#include "localcurrency.h"

class SlotsOpts;

//
// All money values are in cents (100 == $1, 25 == $.25, 1 == $.01)
//
// IMPORTANT:  Access to this class is NOT thread-safe.  That's handled at
//			   the next level up (with calls to lock()/unlock()).
//

class SlotsSQL : public ProgressiveTrackSQL
{
	public:
		SlotsSQL(const String& DBDSN, const String& DBLogin, const String& DBPassword);

		int32 getSubGameData(SubGame *subGame);
        int32 setSubGameData(SubGame *subGame);
        int32 archiveSubGameData(int64 gamenum, SubGame *subGame);
		int32 getFeatureData(Feature *feature);
		int32 setFeatureData(Feature *feature);

        int32 getGuts(SlotGuts *guts);

		int32 getPlayerLimits(const PID& pid, int32 gameId, uint8 machId,
			int32* compFactor);

		int32 saveGame(int32 casinoId, SlotGuts *guts);
		int32 saveSpins(int32 casinoId, SlotGuts *guts);
		int32 saveBonusGames(SlotGuts *guts);

		// CSN-13472 - Rewrite additional AU Slots SPs to use a table-valued parameter
		bool8 saveWins(SlotSpin *spin, ODBCConnection *conn);	
		// CSN-14253 - Rewrite additional AU Slots SPs to use a table-valued parameter
		bool8 saveScatters(SlotSpin *spin, ODBCConnection *conn);	

        int32 getSavedGame(SlotGuts* guts, int32 *gutsid, int64 *gamenum,uint8* bonusgamenum, bool8 *malfunctioned, bool8 *completed, int32* betperline);

		bool8 loadGameDataIntoSpin(int64 gamenum, SlotGuts* guts, SlotSpin* spin);
		bool8 loadWinsDataIntoSpin(SlotSpin* spin, uint8 ucLinesBet);       // kharon.  05-03-07.  #19354.  We no longer save "loser" lines to the database.
		bool8 loadScatterResultsDataIntoSpin(SlotSpin* spin);
		bool8 loadBonusResultsDataIntoSpin(SlotSpin* spin);
		bool8 loadStopsIntoSpin(SlotSpin* spin, uint8 numStops);

		bool8 loadProbabilityTable( SlotGuts *guts, int32 nTableID );
		bool8 getProbabilityTables( SlotGuts *guts );

        int32 deleteSavedGame(int64 gamenum); /// @todo

		bool8 getGutsName(int32 gutsId, char* name);
		bool8 completeGame(SlotGuts *guts);

		bool8 createBonusGame( SlotGuts *guts, int64 gamenum, uint8 bonusgametype, uint8 bonusgameindex, int32 basepayoutamount, int32 totalmultiplier, int32 totalbonuspayoutamount, int32 freespins);
        bool8 GetLocale( localCurrency *localCurr );
        void  getWinAmounts( SlotSpin* spin, int32& totalWin, int32& jackpotWin );

		//used for retreiving the debug spins from the database
		bool8 getDebugSpins (int32 gutsId, DebugStops& stops, int32& numRecords,PID pid);


    private:

        enum ClassConstants
        {
            GAMEID = 18
        };

        bool8 getGutsReels(SlotGuts *guts); 
        bool8 getGutsPayouts(SlotGuts *guts);
        bool8 getGutsPaylines(SlotGuts *guts);
        bool8 getGutsDenominations(SlotGuts *guts);

        int32 createWin(int32 casinoId, 
                    const PID& pid,
                    bool8 forMoney,
                    int32 compFactor,
                    int64 gamenum,
                    uint8 lineid,
                    uint8 payouttypeid,
                    int32 basepayoutamount,
                    int32 totalmultiplier,
                    int32 totallinepayoutamount,
                    int32 *balance,
                    bool8 jackpot,
					ODBCConnection* conn);

        int32 createScatterResults( int64 gamenum, 
                                    uint8 scatterid,
                                    int32 scatterpos, 
                     	            uint8 payouttypeid, 
                                    int32 basepayoutamount,
                                    int32 totalmultiplier,
                                    int32 totalscatterpayoutamount,
                     	            bool8 jackpot,
                                    int32 freespins,
									ODBCConnection* conn );

		int32 createSavedGame(const PID& pid, 
                              uint8 machid, 
                              int16 machsubid, 
                              bool8 forMoney,
                              int64 gamenum,
                              int32 gutsid,
                              uint8 bonusGameNum);


        bool8 getWins(int64 gamenum, SlotSpin *spin); /// @todo
                                                           
        bool8 createWheels(SlotSpin *spin, ODBCConnection* conn);

        bool8 createWheelView(SlotSpin *spin, ODBCConnection* conn);

        bool8 getWheels( int64 gamenum, SlotSpin *spin); /// @todo

        bool8 getGame(int64 gamenum, int32 *bet, uint8 *linesbet, int32 *payout); 

        int32 createLineResultNote(int64 gamenum,
                                   uint8 lineid,
                                   uint8 noteid,
								   ODBCConnection* conn);

        int32 createScatterResultNote(int64 gamenum,
                                      uint8 scatterid,
                                      uint8 noteid,
									  ODBCConnection* conn);
		
		int32 saveBonusGames(SlotGuts *guts, ODBCConnection* conn);

		bool8 createBonusGame( SlotGuts *guts,
							   int64 gamenum,
							   uint8 bonusgametype,
							   uint8 bonusgameindex,
							   int32 basepayoutamount,
							   int32 totalmultiplier,
							   int32 totalbonuspayoutamount,
							   int32 freespins, 
							   ODBCConnection* conn);
        
		int32 createBonusResultNote(int64 gamenum,
									uint8 lineid,
									uint8 noteid, 
									ODBCConnection* conn);

};

#endif
